﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="main.aspx.cs" Inherits="Itop.GpsCar.Web.MainMap.main" %>
<%@ Import Namespace="TreeNode=Ext.Net.TreeNode" %>

<%@ Import Namespace="System.Collections.Generic" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<%--<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        SiteMapNode siteNode = SiteMap.RootNode;
        TreeNode root = this.CreateNode(siteNode);
        root.Draggable = false;
        root.Expanded = true;
        TreePanel1.Root.Add(root);        
    }

    //static node creation with children
    private Ext.Net.TreeNode CreateNode(SiteMapNode siteMapNode)
    {
        TreeNode treeNode = new TreeNode();
        
        treeNode.NodeID = siteMapNode.Key;
        treeNode.Text = siteMapNode.Title;
        treeNode.Qtip = siteMapNode.Description;

        SiteMapNodeCollection children = siteMapNode.ChildNodes;

        if (children != null && children.Count > 0)
        {
            foreach (SiteMapNode mapNode in siteMapNode.ChildNodes)
            {
                treeNode.Nodes.Add(this.CreateNode(mapNode));
            }
        }
        
        return treeNode;
    }
</script>--%>

<SCRIPT>
    (function() {
        function parseURL(url) {
            var a = document.createElement('a');
            a.href = url;
            return {
                source: url,
                protocol: a.protocol.replace(':', ''),
                host: a.hostname,
                port: a.port,
                query: a.search,
                params: (function() {
                    var ret = {},
					seg = a.search.replace(/^\?/, '').split('&'),
					len = seg.length, i = 0, s;
                    for (; i < len; i++) {
                        if (!seg[i]) { continue; }
                        s = seg[i].split('=');
                        ret[s[0]] = s[1];
                    }
                    return ret;
                })(),
                file: (a.pathname.match(/\/([^\/?#]+)$/i) || [, ''])[1],
                hash: a.hash.replace('#', ''),
                path: a.pathname.replace(/^([^\/])/, '/$1'),
                relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [, ''])[1],
                segments: a.pathname.replace(/^\//, '').split('/')
            };
        }
        var url = parseURL(window.location.href);
        //全局变量
        custid = url.params.custid; //随树的点击而改变
        pid = url.params.pid;
        custname = unescape(url.params.custname);
        document.title = custname;
        lang = url.params.lang || "cn";
        mds = url.params.mds;
        mapType = url.params.mapType || (lang == 'en' ? 'GOOGLE' : "BAIDU");
        loginCustId = custid; //不改变
        loginUrl = decodeURI(url.params.loginUrl).replace(/1\./g, '.');
        monitorUrl = decodeURI(url.params.monitorUrl || '').replace(/1\./g, '.');
        isViewCust = (1000003 == custid);
        GLtax = (isViewCust) ? "0" : "1";

        requestSource = url.params.requestSource || 'web';

    })();
    </SCRIPT>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <link href="../resources/css/examples.css" rel="stylesheet" type="text/css" />
    
    <script type="text/javascript">
        var deviceid;
        var filterTree = function(el, e) {
            var tree = TreePanel1,
                text = this.getRawValue();

            tree.clearFilter();

            if (Ext.isEmpty(text, false)) {
                return;
            }

            if (e.getKey() === Ext.EventObject.ESC) {
                clearFilter();
            } else {
                var re = new RegExp(".*" + text + ".*", "i");

                tree.filterBy(function(node) {
                    return re.test(node.text);
                });
            }

        };

        var deviceID = function(el, e) {
            var tree = TreePanel1,
                text = this.getRawValue();

            tree.clearFilter();

            if (Ext.isEmpty(text, false)) {
                return;
            }

            if (e.getKey() === Ext.EventObject.ESC) {
                clearFilter();
            } else {
                var re = new RegExp(".*" + text + ".*", "i");

                tree.filterBy(function(node) {
                return re.test(node.NodeID);
                });
            }

        };

        var clearFilter = function() {
            var field = TriggerField1,
                tree = TreePanel1;

            field.setValue("");
            tree.clearFilter();
            tree.getRootNode().collapseChildNodes(true);
            tree.getRootNode().ensureVisible();
        };
    </script>
</head>
<body>
    <form id="Form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />           
        
        <ext:Panel ID="Window1" runat="server" Title=""  Height="620"  Layout="column">
        <Items>
       
        <ext:TreePanel 
            ID="TreePanel1"
            runat="server" 
            Height="300" 
            Width="250"
            UseArrows="true"
            AutoScroll="true"
            Animate="true"
            EnableDD="true"
            ContainerScroll="true">           
            <TopBar>
                <ext:Toolbar ID="Toolbar1"  runat="server">
                    <Items>
                        <ext:ToolbarTextItem ID="ToolbarTextItem1" runat="server" Text="选择:" />
                        <ext:ToolbarSpacer />
                        <ext:TriggerField ID="TriggerField1" Width="100" runat="server" EnableKeyEvents="true">
                            <Triggers>
                                <ext:FieldTrigger Icon="Clear" />
                            </Triggers>                            
                            <Listeners>
                                <KeyUp Fn="filterTree" Buffer="250" />
                                <TriggerClick Handler="clearFilter();" />
                            </Listeners>
                        </ext:TriggerField>   
                         <ext:Button ID="Button1" runat="server" Text="跟踪" ToggleGroup="editor" Pressed="true">
                            <Listeners>
                                <Click  Handler="window.open('Tracking.aspx');" />                                
                            </Listeners>
                        </ext:Button>
                        
                        <ext:Button ID="Button2" runat="server" Text="回放" ToggleGroup="editor">
                            <Listeners>
                                <Click Handler="window.open('PlayBack.aspx');" />
                            </Listeners>
                        </ext:Button>
                     
                    </Items>
                </ext:Toolbar>
            </TopBar>      


        </ext:TreePanel>
         <ext:Panel ID="Panel2" runat="server" Title="" Padding="10" ColumnWidth="0.8">
                    <AutoLoad Url="map.aspx" Mode="IFrame" ShowMask="true" />                                
       </ext:Panel>

             </Items>
        </ext:Panel>   

    </form>
</body>
</html>
